using System.Collections.Generic;
using System.Xml;

namespace Kotonoha.Server.Xml {
    public class ParentHandler : ElementHandler {

        readonly Dictionary<string, ElementHandler> handlers = new Dictionary<string, ElementHandler>();

        public ParentHandler(string name) : base(name) {
        }

        public void Add(ElementHandler child) {
            handlers.Add(child.name, child);
        }

        protected override void readBody(XmlReader reader) {
            while (reader.NodeType != XmlNodeType.EndElement && !reader.Name.Equals(name)) {
                ElementHandler handler;
                if (handlers.TryGetValue(reader.Name, out handler)) {
                    handler.read(reader);
                } else {
                    reader.Skip();
                }
            }
        }
    }
}